\ Jun 92 32-bit 68000 code moved to main dic. Removed / and /mod from here
\ since main dic versions are now 32-bit.
\ Sept 92 Revised to support the ANSI standard.
\ This file implements double-length (64 bit) addition and subtraction, 32*32->64 multiplication and 64/32->32 division, and versions of */ and */MOD which have a 64-bit intermediate result.
\ This behavior is required by the ANSI standard, defined in terms of cells. It may be overkill for Mops which has 32-bit cells, so we don't put it in the nucleus, but provide it here as an option.
:code S>D
loc
move (a6),d0
bmi.s mn ; This is quicker than two EXT's
clr.l -(a6)
rts
mn moveq #-1,d0
push.l d0
;code
:code DNEG
neg 4(a6)
negx (a6)
;code
:code D+
movem (a6)+,d0-d2
add d1,(a6)
addx d0,d2
push d2
;code
:code D-
movem (a6)+,d0-d2
sub d1,(a6)
subx d0,d2
push d2
;code
:code D< loc
movem (a6)+,d0-d2
cmp d0,d2
blt.s setTrue
bgt.s setFalse
cmp (a6),d1
bhi.s setTrue
setFalse
clr (a6)
rts
setTrue moveq #-1,d0
move d0,(a6)
;code
:code D>
movem (a6)+,d0-d2
cmp d0,d2
bgt.s setTrue
blt.s setFalse
cmp (a6),d1
blo.s setTrue
bra.s setFalse
;code
:code D=
movem (a6)+,d0-d2
cmp d0,d2
bne.s setFalse
cmp (a6),d1
bne.s setFalse
bra.s setTrue
;code
\ The somewhat dreaded multiply routines
:code LONGMULT ; Subroutine to do long unsigned multiply. Uses D0-2.
loc
pop.l d0
move.l (a6),d1
clr.l -(a6)
move.w d1,d2
mulu d0,d2
move.l d2,4(a6)
move.l d1,d2
swap d2
mulu d0,d2
add.l d2,2(a6)
swap d0
move.w d1,d2
mulu d0,d2
add.l d2,2(a6)
bcc.s mpy2
addq.w #1,(a6)
mpy2 move.l d1,d2
swap d2
mulu d0,d2
add.l d2,(a6)
;code
:code UM* ; Unsigned mixed multiply
loc
bra.s p68k ; NOP'd out if we're on an 020/030 or later
pop.l d1
dc.w $4C16,$1400 ; mulu.l (a6),d0:d1
move.l d1,(a6)
push.l d0
rts
p68k tst.w (a6) ; If both high-order words are zero,
bne.s dic[longMult] ; we can do a short multiply.
tst.w 4(a6)
bne.s dic[longMult]
pop.l d0 ; Yes, we can.
move.l (a6),d1
mulu d0,d1
move.l d1,(a6)
clr.l -(a6)
;code
:code M* ; Signed mixed multiply
loc
bra.s p68k ; NOP'd out if we're on an 020/030 or later